// 辅导人员信息
<template>
  <div class="app-container">
    <el-row>
      <!--用户数据-->
      <el-col :span="24">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          v-show="showSearch"
          label-width="68px"
        >
          <el-form-item label="学 校" prop="schoolId">
            <el-select
              v-model="queryParams.schoolId"
              placeholder="选择全部"
              clearable
              style="width: 240px"
              @change="schoolChange"
            >
              <el-option
                v-for="item in schoolLiat"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="量 表" prop="nation">
            <el-select
              v-model="queryParams.nation"
              placeholder="选择全部"
              clearable
              style="width: 240px"
            >
              <el-option
                v-for="dict in scaleList"
                :key="dict.id"
                :label="dict.title"
                :value="dict.id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="姓 名" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入学生姓名"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>

          <el-form-item label="创建时间">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>
        <el-table
          v-loading="loading"
          :data="userList"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column
            label="姓名"
            align="center"
            key="name"
            prop="name"
            width="100"
          />
          <el-table-column
            label="联系方式"
            align="center"
            key="phoneNum"
            prop="phoneNum"
            :show-overflow-tooltip="true"
          />

          <el-table-column
            label="性别"
            align="center"
            key="sexDictText"
            prop="sexDictText"
            width="60"
          />
          <el-table-column
            label="民族"
            align="center"
            key="nation"
            prop="nation"
            width="100"
          />

          <el-table-column
            label="所属学校"
            align="center"
            key="schoolName"
            prop="schoolName"
            width="120"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="班级"
            align="center"
            key="className"
            prop="className"
            width="120"
          />

          <el-table-column label="状态" align="center" key="flag">
          </el-table-column>
          <el-table-column
            label="测评量表"
            align="center"
            key="phoneNum"
            prop="phoneNum"
            :show-overflow-tooltip="true"
          />
          <el-table-column
            label="测评结果"
            align="center"
            key="phoneNum"
            prop="phoneNum"
            :show-overflow-tooltip="true"
          />
          <el-table-column label="预警等级" align="center" key="flag">
            <template slot-scope="scope">
              <div>
                {{ selectDictLabels(dict.type.sys_label_type, scope.row.flag) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="预约时段" align="center" key="flag">
            <template slot-scope="scope">
              <div>
                {{ selectDictLabels(dict.type.sys_label_type, scope.row.flag) }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            width="160"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit-outline"
                @click="handleAdd(scope.row)"
                v-hasPermi="['system:user:edit']"
                >办理</el-button
              >
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:user:remove']"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改学生信息对话框 -->
    <el-dialog title="办理" :visible.sync="open" width="800px" append-to-body>
      <el-form label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="学生姓名" prop="name">
              <el-input v-model="pupilProfile.name" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="sexDictText">
              <el-input v-model="pupilProfile.sexDictText" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="年龄" prop="age">
              <el-input v-model="pupilProfile.age" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="民族" prop="nation">
              <el-input v-model="pupilProfile.nation" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属学校" prop="schoolName">
              <el-input v-model="pupilProfile.schoolName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="班级" prop="className">
              <el-input v-model="pupilProfile.className" disabled />
            </el-form-item>
          </el-col>
        </el-row>
          <el-row>
          <el-col :span="12">
            <el-form-item label="测评量表" prop="schoolName">
              <el-input v-model="pupilProfile.schoolName" disabled />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="测评结果" prop="className">
              <el-input v-model="pupilProfile.className" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="预约时段" prop="">
              <el-input />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否预约" prop="ifPsy">
               <el-radio-group v-model="pupilProfile.ifPsy" >
                <el-radio
                  v-for="dict in dict.type.yes_no_switch"
                  :key="dict.value"
                  :label="dict.value"
                  >{{ dict.label }}</el-radio
                >
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input
                v-model="pupilProfile.remark"
                type="textarea"
                placeholder="请输入内容"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  schoolPage, //获取学校
  personStudent, //新增学生
  personStudentPut, //修改学生信息
  studentPage, //获取学生信息

  delDent, //删除学生
  classPull, //获取班级
} from "@/api/information/index";
import {
  formcfgList, //量表列表
} from "@/api/itemBank/index";

export default {
  name: "User",
  dicts: ["sys_normal_disable", "sys_user_sex", "sys_label_type","yes_no_switch"],
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      names: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open:false,

      // 表单参数
      form: {},

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 学校信息
      schoolLiat: [],
      //   班级
      classlLiat: [],
      // 名族
      nationLiat: [],
      visibleSync: false,
      pupilProfile: {},
  

      scaleList: [],
      // 表单校验
      rules: {
        name: [
          { required: true, message: "学生姓名不能为空", trigger: "blur" },
          {
            // min: 2,
            // max: 20,
            // message: "用户名称长度必须介于 2 和 20 之间",
            trigger: "blur",
          },
        ],
        schoolId: [
          { required: true, message: "所属学校不能为空", trigger: "blur" },
        ],
        studentCode: [
          { required: true, message: "所属学籍号不能为空", trigger: "blur" },
        ],
        classId: [
          {
            required: true,
            message: "请先选择有班级的学校,班级不能为空",
            trigger: "blur",
          },
        ],
        email: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        phoneNum: [
          { required: true, message: "联系方式不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  watch: {},
  created() {
    this.getschool();
    this.getList();

    this.getNormalScale();
  },
  methods: {
    // 获取正常量表
    getNormalScale() {
      // usingStatus: 0 //启用状态
      formcfgList({ usingStatus: 0, examType: 1 }).then((response) => {
        this.scaleList = response.rows;
      });
    },

    // 获取学校
    getschool() {
      schoolPage({ type: 2 }).then((res) => {
        this.schoolLiat = res.rows.map((item) => {
          return {
            value: item.id,
            label: item.name,
          };
        });
      });
    },
    //班级
    schoolChange(val) {
      this.classlLiat = [];
      console.log("数据", val);
      if (val) {
        classPull(val).then((res) => {
          this.classlLiat = res.data;
          if (this.classlLiat.length == 0) {
            this.form.classId = "";
          }
        });
      }
    },
    // 查询
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.userId);
      this.single = selection.length !== 1;
    },
    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      // studentPage(this.queryParams).then((res) => {
      //   console.log("获取", res);
      //   // this.userList = res.rows;
      //   this.total = res.total;
        this.loading = false;
      // });
    },
    accessSchool(data) {
      this.queryParams.pageNum = 1;
      this.queryParams.schoolId = data.id.toString();
      this.getList();
      console.log("学校信息", data);
    },

    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: undefined,

        userName: undefined,
        nickName: undefined,
        password: undefined,
        phonenumber: undefined,
        email: undefined,
        sex: undefined,
        status: "0",
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      // this.$refs.tree.setCurrentKey(null);
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.names = selection.map((item) => item.name);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 查看按钮操作 */
    handleAdd(row) {
      this.open = true;
      this.pupilProfile = row;
      this.title = "办理";
      this.reset();
    },

    /** 提交按钮 */
    submitForm: function () {
      this.schoolLiat.forEach((element) => {
        if (this.form.schoolId == element.value) {
          this.form.schoolName = element.label;
        }
      });
      this.classlLiat.forEach((element) => {
        if (this.form.classId == element.key) {
          this.form.className = element.value;
        }
      });
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != undefined) {
            personStudentPut(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            personStudent(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.id || this.ids;
      const namec = row.name || this.names;
      this.$modal
        .confirm('是否确认删除用户编号为"' + namec + '"的数据项？')
        .then(function () {
          return delDent(userIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
};
</script>
<style lang="scss" scoped>
.labelys {
  width: 100%;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
  div:nth-child(1) {
    width: 10px;
    height: 10px;
    background-color: red;
    margin-right: 10px;
  }
}
.tater {
  margin-bottom: 10px;
  .uncheck {
    width: 80px;
    height: 25px;
    line-height: 25px;
    text-align: center;
    color: #1890ff;
  }
}
</style>
